<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    	<!--<link rel="stylesheet" href="Public/Bootstrap/Css/bootstrap.min.css" />-->
	    	<!-- 需要载入的文件 -->
	    <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
	    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
	    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
	    	<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.all.min.js"> 			</script>
    		<script type="text/javascript"charset="utf-8"src="Public/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <script>
			$(function(){			
				
				$('select[name=category_cid]').blur(function(){
					  var tid=$('option:selected').attr('tid');
					  			$.ajax({
					  				type:"post",
					  				url:"<?php echo U('Goods/getAttr')?>",
					  				data:{tid:tid},
					  				dataType:'json',
					  				success:function(phpData){
					  					var attr='';
					  					var spec='';
					  					$.each(phpData,function(k,v){
//					  						如果是属性
					  						if(v.choose==0){
					  							attr+='<tr>';
												attr+='<td class="success">'+v.taname+'</td>';
												attr+='<td>';
												attr+='<select name="attr['+v.taid+']" id="" class="form-control input-sm">';
												attr+='<option value=""  >请选择</option>';
														$.each(v.tvalue,function(kk,vv){
												attr += '<option value="'+vv+'">'+vv+'</option>';
												});
												attr+='</select>';
												attr+='</td>';
												attr+='</tr>';
					  						}else{//否则是规格
					  							spec+='<tr>';
												spec+='<td class="success">'+v.taname+'</td>';
												spec+='<td>';
//												console.log(v);
												spec+='<select name="spec[value]['+v.taid+'][]" id="" class="form-control input-sm">';
												spec+='<option value=""  >请选择</option>';
														$.each(v.tvalue,function(kk,vv){
															console.log(vv);
												spec += '<option value="'+vv+'">'+vv+'</option>';
												});
												spec+='</select>';
												spec+='</td>';
												spec+='<td class="success">附加价格：<input type="text" name="spec[addprice]['+v.taid+'][]" /></td>';																				
												spec+='<td><a href="javascript:;" class="btn btn-primary addSpec">添加规格</a></td>';
												spec+='</tr>';
					  						}
					  
					  					});
					  					$('#attr').html(attr);
					  					$('#spec').html(spec);
					  				}
					  				
					  			});					  			
				})
//				添加规格 绑定点击事件
				$('.addSpec').live('click',function(){

					var trObj=$(this).parents('tr');
//					克隆一个tr
					var tr=trObj.clone();
					tr.find('.addSpec').html('删除规格').removeClass("Primary addSpec").addClass("btn btn-danger removeSpec");
//					插到当前父级的下面
					trObj.after(tr);
				})
				$('.removeSpec').live('click',function(){
				$(this).parents('tr').remove();
			})
			})
	    </script>
	</head>
	<body>
		<form action="" method="post" enctype="multipart/form-data">
		<div class="alert alert-success">添加商品</div>
		<div class="form-group">
			<label for="exampleInputEmail1">所属分类</label>
			<select name="category_cid" class="form-control shuxing">
				<option value="">请选择</option>
				<?php foreach ($category as $v){?>
				<option value="<?php echo $v['cid']?>" tid=<?php echo $v['type_tid']?>><?php echo $v['_name']?></option>
				<?php }?>
			</select>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">所属品牌</label>
			<select name="brand_bid" class="form-control">
				<option value="">请选择</option>
				<?php foreach ($brand as $v){?>
				<option value="<?php echo $v['bid']?>"><?php echo $v['bname']?></option>
				<?php }?>
			</select>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">商品名称</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder=""  name="gname">
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">单位</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder=""  name="unit">
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">价格</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder=""  name="price">
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">库存</label>
			<input id="exampleInputEmail1" class="form-control" type="text" placeholder=""  name="inventorys">
		</div>
		<div class="form-group sx">
			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
			
				
			</table>
		</div>		
		<div class="form-group">
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id="spec"  class="info">
			
				
			</table>
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">列表图</label>			
			<div lab="uploadFile">
				<input id="f" type="file" multiple="true" />
				<span>类型：*.jpg,*.jpeg,*.png,*.gif 大小：2000kb 数量1</span>
				<script type="text/javascript">
					$(function(){
						$('#f').uploadify({
							'formData':{
								'<?php echo session_name(); ?>':'<?php echo session_id();?>',
								},//POST数据					
							'fileTypeExts':'*.jpg;*.jpeg;*.png;*.gif',//支持上传的格式
							'swf':'<?php echo __PUBLIC__?>/uploadify/uploadify.swf',					
							'uploader':'<?php echo U('upload')?>',		//指定上传的方法
							'buttonText':'选择图片',				//提示文字
							'fileSizeLimit':'2000KB',				//可上传大小
							'uploadLimit':1,								//每次可上传数量
							'width':65,									//图片的宽
							'height':30,								//图片的高
							'successTimeout':10,                   //等待服务器响应时间
							'removeTimeout':0.2,				//成功显示时间
							'onUploadSuccess':function(file, data, response){   //接收PHP返回的数据
								data=$.parseJSON(data);
								var imageUrl = data.url;
								var li="<li>";
								 li += "<img src='"+imageUrl+"'/>",
								 li += "<input type='hidden' name='listimg' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
                    			 li += "</li>";
                    			$("#uploadList ul").prepend(li);
                }
            });

			//关闭图片
            var i = 1;
            $('#self-close').live('click',function(){
                $(this).parent('li').remove();
                i++;
                $('#f').uploadify('settings','uploadLimit',i);
            })
								 
//							}
//						})
					});
				</script>
			
			</div>
			<div id="uploadList">
				<ul>
					
				</ul>
			</div>
			
		</div>
		<div class="form-group">
			<label for="exampleInputEmail1">商品图</label>
				<div lab="uploadFile">
					<input id="d" type="file" multiple="true" />
					<span>类型：*.jpg,*.jpeg,*.png,*.gif 大小：2000kb 数量1</span>
					<script type="text/javascript">
						$(function(){
							$('#d').uploadify({
								'formData':{
									'<?php echo session_name(); ?>':'<?php echo session_id();?>',
									},//POST数据					
								'fileTypeExts':'*.jpg;*.jpeg;*.png;*.gif',//支持上传的格式
								'swf':'<?php echo __PUBLIC__?>/uploadify/uploadify.swf',					
								'uploader':'<?php echo U('upload')?>',		//指定上传的方法
								'buttonText':'选择图片',				//提示文字
								'fileSizeLimit':'2000KB',				//可上传大小
								'uploadLimit':1,								//每次可上传数量
								'width':65,									//图片的宽
								'height':30,								//图片的高
								'successTimeout':10,                   //等待服务器响应时间
								'removeTimeout':0.2,				//成功显示时间
								'onUploadSuccess':function(file, data, response){   //接收PHP返回的数据
									data=$.parseJSON(data);
									var imageUrl = data.url;
									var li="<li>";
									 li += "<img src='"+imageUrl+"'/>",
									 li += "<input type='hidden' name='listimgs' value='"+data.path+"'/><a href='javascript:;' id='self-close'>X</a>";
	                    			 li += "</li>";
	                    			$("#uploadLists ul").prepend(li);
	                }
	            });
	
				//关闭图片
	            var i = 1;
	            $('#self-close').live('click',function(){
	                $(this).parent('li').remove();
	                i++;
	                $('#f').uploadify('settings','uploadLimit',i);
	            })
									 
	//							}
	//						})
						});
					</script>
				
				</div>
				<div id="uploadLists">
					<ul>
						
					</ul>
				</div>
			</div>
		
		<div class="form-group">
			<label for="exampleInputEmail1">文章正文</label>
			<!--调用百度编辑器-->
			<script id="editor" type="text/plain" style="width:100%;height:500px;" name="gdetail"></script>
		    <script>
		        var ue = UE.getEditor('editor');
		    </script>
		</div>
		<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
		</form>
	</body>
</html>
